<?php
namespace app\admin\controller\system;
use app\common\controller\AdminController;
use think\facade\View;


/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/22 0022
 * Time: 10:24
 */
class Word extends AdminController
{
    public function initialize()
    {
        parent::initialize();
        $this->model = app('app\common\model\system\Word');
        $this->field='id,content,status,number,admin_id,create_time';
    }
    /**
     * 列表
     */
    public function get_where($arr=[]){
        $array=[];
        if(!empty($arr['name'])){
            $array[] = ['name','like','%'.$arr['name'].'%'];
        }
        return $array;
    }
    /**
     * 获取验证规则
     * @param $post
     * @return array
     */
    public function get_check_rule()
    {
        $rule = [
            'content|敏感词'   => 'require|unique:word',
        ];

        return $rule;
    }
    /**
     * 状态
     */
    public function action()
    {
        $require = $this->request->param();
        try{

            $data = $this->model->where('id',$require['id'])->find();
            $data->save(['status'=>$require['status']]);
            return json(['code'=>0,'msg'=>'更新成功']);
        }catch (\Exception $exception){
            return json(['code'=>1,'msg'=>$exception->getMessage()]);
        }
    }

}